class CellNode extends egret.Sprite {
	public static TYPE1: number;
	public static TYPE2: number;
	public static TYPE3: number;
	public static TYPE4: number;
	public static TYPE5: number;
	private _angle: number = 0;
	private _radius: number = 0;
	private _type: number = 0;
	private _sync: Sync = null;
	private _color: number = 0;

	public constructor(type: number, radius: number, angle: number, color: number) {
		super();
		this._type = type;
		this._radius = radius;
		this._angle = ((angle * Math.PI) / 180);
		this._color = color;
		this._sync = new Sync(0.3);
		this.setRadius(radius);
		var tendril: Tendril;
		var pulsar: Pulsar;
		switch (this._type) {
			case CellNode.TYPE1:
				tendril = new Tendril(Tendril.TYPE_WITHOUT_SPOT, 0, 0, 10, 0.3);
				this.addChild(tendril);
				return;
			case CellNode.TYPE2:
				pulsar = new Pulsar(0, 0, color, 4);
				tendril = new Tendril(Tendril.TYPE_WITHOUT_SPOT, 0, 0, 15, 0.3);
				pulsar.addChildNode(tendril);
				this.addChild(pulsar);
				return;
			case CellNode.TYPE3:
				pulsar = new Pulsar(0, 0, color, 4);
				tendril = new Tendril(Tendril.TYPE_WITH_SPOT, 0, 0, 15, 0.3);
				tendril.setColor(this._color);
				pulsar.addChildNode(tendril);
				this.addChild(pulsar);
				return;
			case CellNode.TYPE4:
				pulsar = new Pulsar(0, 0, color, 4);
				pulsar.addChildNode(new Pulsar(0, -60, color, 3), 5);
				pulsar.addChildNode(new Pulsar(0, 60, color, 3), 5);
				pulsar.addChildNode(new Tendril(Tendril.TYPE_WITHOUT_SPOT, 0, -20, 15, 0.3));
				pulsar.addChildNode(new Tendril(Tendril.TYPE_WITHOUT_SPOT, 0, 20, 15, 0.3));
				this.addChild(pulsar);
				return;
			case CellNode.TYPE5:
				pulsar = new Pulsar(0, 0, color, 5);
				tendril = new Tendril(Tendril.TYPE_WITH_SPOT, 0, 0, 20, 0.3);
				tendril.setColor(this._color);
				pulsar.addChildNode(tendril);
				pulsar.addChildNode(new Pulsar(0, 0, color, 3, 40), 5);
				pulsar.addChildNode(new Pulsar(0, 120, color, 3, 40), 5);
				pulsar.addChildNode(new Pulsar(0, 240, color, 3, 40), 5);
				this.addChild(pulsar);
				return;
		}
	}

	public setRadius(radius: number) {
		this._radius = radius;
		this.x = (Math.cos(this._angle) * this._radius);
		this.y = (Math.sin(this._angle) * this._radius);
		this.rotation = ((this._angle * 180) / Math.PI);
	}

	public destruct() {
		var node: com.Node;
		while (this.numChildren > 0) {
			node = this.removeChildAt(0) as com.Node;
			node.destruct();
		}
	}

}

CellNode.TYPE1 = 1;
CellNode.TYPE2 = 2;
CellNode.TYPE3 = 3;
CellNode.TYPE4 = 4;
CellNode.TYPE5 = 5;

